import sys
import paramiko
import getpass

def ssh_connect(ip,username,password,port=22):
    try:
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(ip,username,password,port)
        while 1:
            stdin, stdout, stderr = ssh.exec_command(input("#"))
            print(stderr.read().decode())
            print(stdout.read().decode())
    except paramiko.AuthenticationException as ae:
        print("Authentication Failed")
    except paramiko.SSHException as ssh_exception:
        print("SSH Connection Failed:",ssh_exception)
    except KeyboardInterrupt as e:
        ssh.close()
    
if __name__ == "__main__":
    args=sys.argv
    ip=args[1].split('@')[1]
    username=args[1].split('@')[0]
    password=getpass.getpass()
    port=input("Port or 22:")
    if port==None:
        port=22
    port=int(port)
    ssh_connect(ip,username,password,port)